import machine 
from machine import Pin,PWM,UART
import time
uart = UART(id, baudrate=9600, tx=Pin(28), rx=Pin(27), bits=8, parity=None, stop=1)
led=Pin(2,Pin.OUT)
led.value(1)
#led指示灯
data=uart.read()
uart.write('SE OK')
PWM_PINS = [Pin(3, Pin.OUT), Pin(8, Pin.OUT), Pin(9, Pin.OUT),
            Pin(10, Pin.OUT), Pin(19, Pin.OUT), Pin(18, Pin.OUT)]

timer = Timer(0)
timer.init(freq=1000)  # 设置 PWM 频率为 1kHz

# 初始化 PWM 通道
pwm_channels = [timer.channel(i + 1, Timer.PWM, pin=pin) for i, pin in enumerate(PWM_PINS)]
steps = [
    [1, 0, 0, 0, 0, 0],  # 第一步
    [1, 1, 0, 0, 0, 0],  # 第二步
    [0, 1, 0, 0, 0, 0],  # 第三步
    [0, 1, 1, 0, 0, 0],  # 第四步
    [0, 0, 1, 0, 0, 0],  # 第五步
    [0, 0, 1, 1, 0, 0],  # 第六步
]

def set_pwm_duty(step, duty_cycle):
    for i, pwm in enumerate(pwm_channels):
        pwm.pulse_width_percent(steps[step][i] * duty_cycle)


while True:
    data = uart.read()
    if data==b'ready':
        set_pwm_duty(0, 50)
        #下接控制程序